#pragma once
#include <osg/PrimitiveSet>

#include "Ent.h"
#include "Plane.h"

class JsonReader;

struct Arc3DPrivate;
class Arc3D : public Ent3DCurve, public Plane
{
	Q_OBJECT
public:
	Arc3D(INode* parent);
	virtual std::shared_ptr<Ent> clone() const override;
	void set(const osg::Vec3d& center, double radius, float startAngle, float endAngle);
	void setCircle(const osg::Vec3d &center, const double radius);
	bool setCircle3P(const osg::Vec3d& p0, const osg::Vec3d& p1, const osg::Vec3d& p2);
	bool set3P(const osg::Vec3d& p0, const osg::Vec3d& p1, const osg::Vec3d& p2);
	bool setCSE(const osg::Vec3d& center, const osg::Vec3d& start, const osg::Vec3d& end);
	bool setCircleCSE(const osg::Vec3d& center, const osg::Vec3d& start, const osg::Vec3d& end);
	void setColor(const osg::Vec4 &color);
	// change center to make origin to be (0, 0, 0)
	void normalize();
	const osg::Vec4& color() const;
	const osg::Vec3d& center() const;
	double radius() const;
	float startAngle() const;
	float endAngle() const;
	virtual void update3D() override;
	virtual osg::Node* getRep3D() const override;
	virtual void setSelected(bool val) override;
	virtual void save(QJsonObject &json) const;
	virtual void load(const QJsonObject& json, JsonReader& reader);
	virtual void move(const osg::Vec3d& offset) override;
	virtual void scale(const osg::Vec3d& center, double scale) override;
	virtual std::vector<osg::Vec3d> handles() const override;
	virtual void stretch(int index, const osg::Vec3d &offset) override;
	virtual void copy(const Ent& ent) override;
	virtual std::vector<Handle(Geom_Curve)> getCurve3d() const override;
	virtual void rotate(const double angle, const osg::Vec2d& basePoint) override;
	LEAF_METHODS;

protected:
	void calHandles() const;

	Arc3DPrivate* d_ptr;
};
